// Copyright DustedPixels.com 2008. All rights reserved.

package kroff.opt;

/**
 * After injecting thousandToOne
 */
public final class TopLevel2 {

  private final Runnable thousandToOne_everyTime;
  private final Runnable thousandToOne_onceInThousand;
  private int thousandToOne_counter = 0;

  public TopLevel2(Runnable external) {
    this.thousandToOne_everyTime = new Incrementor(new Counter());
    this.thousandToOne_onceInThousand = external;
  }
  
  public void run() {
    thousandToOne_run();
  }

  private void thousandToOne_run() {
    thousandToOne_everyTime.run();
    if (thousandToOne_counter == 0) {
      thousandToOne_onceInThousand.run();
    }
    thousandToOne_counter = (thousandToOne_counter + 1) % 1000;
  }

}
